package cn.dong.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 网关配置
 */
@Configuration
public class GatewayConfig {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();

        // 配置edu服务
        // id
        routes.route("service-edu8000",
                // 路径
                r -> r.path("/*/edu/**", "/edu/**")
                        // 断言路径
                        .uri("lb://service-edu8000")).build();

        // 配置cms服务
        routes.route("service-cms8001",
                r -> r.path("/*/cms/**", "/cms/**")
                        .uri("lb://service-cms8001")).build();
        // 配置sms服务
        routes.route("service-sms5000",
                r -> r.path("/*/sms/**", "/sms/**")
                        .uri("lb://service-sms5000")).build();

        // 配置order服务
        routes.route("service-order8899",
                r -> r.path("/*/order/**", "/order/**")
                        .uri("lb://service-order8899")).build();

        // 配置ucenter服务
        routes.route("service-ucenter8160",
                r -> r.path("/*/ucenter/**", "/ucenter/**")
                        .uri("lb://service-ucenter8160")).build();

        // 配置oss
        routes.route("service-oss7000",
                r -> r.path("/*/oss/**", "/oss/**")
                        .uri("lb://service-oss7000")).build();

        // 配置vod服务
        routes.route("service-vod9000",
                r -> r.path("/*/vod/**", "/vod/**")
                        .uri("lb://service-vod9000")).build();

        // 配置statistics服务
        routes.route("service-statistics8555",
                r -> r.path("/*/statistics/**", "/statistics/**")
                        .uri("lb://service-statistics8555")).build();

        return routes.build();
    }

}
